from time import sleep

import requests
import time
import hashlib
import asyncio
import aiohttp


async def fetch(session, url, headers, cookies):
    async with session.post(url, headers=headers, cookies=cookies, data='{}') as response:
        return await response.json()


async def main():
    url = 'https://gateway.cotticoffee.com/cotti-capi/address/listForOrder'
    headers = {
        "Connection": "keep-alive",
        "Content-Length": "2",
        "program-version": "3.5.0",
        "version": "1.0.0",
        "split_timestamp": "0",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581",
        "Content-Type": "application/json",
        "xweb_xhr": "1",
        "api-version": "v5",
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ7XCJpc05ld01lbWJlclwiOmZhbHNlLFwibWVtYmVySWRcIjoyMTQ4MjI1NTM0MCxcIm1lbWJlck5vXCI6XCIyMTQ4MjI1NTM0MFwiLFwibWVtYmVyVHlwZVwiOjAsXCJtb2JpbGVcIjpcIjE4MzIzNDA2NzAwXCIsXCJvcGVuSWRcIjpcIm9ROVpWNVBGRjdnam1xN0RtbUFteFZyTTNLbDBcIixcInRlcm1pbmFsVHlwZVwiOlwiOTAxXCIsXCJ1bmlvbklkXCI6XCJvMlNfTDUyQzNhVjJxc3hUZ0trYkoxWXg4aE5RXCIsXCJ2ZXJzaW9uXCI6MTczNTYzNDk3NTE5Nn0iLCJpc3MiOiJjb3R0aSIsImV4cCI6MTc0MDgxODk3NSwiaWF0IjoxNzM1NjM0OTc1LCJqdGkiOiIwZDk5YzQ5ZWViZDE0MzI5OGE1ZjU1M2M1YTQ3ZTU2OCJ9.BekOk6BcPiia4hjbsf67f9Pow2S3JFmVqA3be0nBpVc",
        "appKey": "QbGDuwcCztkquMfyw4Q3hyiiDDa0NYTz",
        "app-version": "209",
        "Accept": "*/*",
        "Sec-Fetch-Site": "cross-site",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Dest": "empty",
        "Referer": "https://servicewechat.com/wxe766d738ad655e8c/132/page-frame.html",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9"
    }
    cookies = {}
    tasks = []
    async with aiohttp.ClientSession() as session:
        while True:

            time1 = int(time.time() * 1000)
            s = f'path/cotti-capi/address/listForOrdertimestamp{str(time1)}version1.0.0k9k16jSJaXj46QLElEVT8uRme2uHrtee'
            sign = hashlib.md5(s.encode()).hexdigest().upper()
            print(sign)
            headers['timestamp'] = str(time1)
            headers['sign'] = sign
            response = await fetch(session, url, headers, cookies)
            print(response)  # 打印每个任务的结果
            await asyncio.sleep(0.01)

start_time = time.time()
print('开始时间:', start_time)
asyncio.run(main())
end_time = time.time()
print('结束时间', end_time)
# 计算开始时间和结束时间
print('时间消耗:', end_time - start_time)


# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{"cid":"","keyword":"","size":15,"page":1}'
